<?php
	session_start();

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Best jokes</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" href="css/styles.css" />
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
	<link rel="stylesheet" href="js/colorbox/example1/colorbox.css" type="text/css" />
	<script src="js/colorbox/colorbox/jquery.colorbox-min.js" type="text/javascript"></script>
	<script type="text/javascript">		
		$(document).ready(function() {
				$(".link").colorbox({ fastIframe:false ,width:"600px", height:"400px"});
		});
		</script>

</head>

<body>
	<div id="wrapper" class="container_12 clearfix">
			<div id="entete">
				<h1 style="float:left;"> jokebook</h1>
				<div class="proposition">
					<?php
						if(isset($_SESSION["id_user"])){
							$id_user=$_SESSION["id_user"];
							echo '
							<br />
								<a href="insert_joke.php" title="joke" class="link"> SHARE YOUR JOKE </a>
							';
						}
					?>
				</div>
				<div class= "lien" style="float:right;">
					<?php
						if(isset($_SESSION["id_user"])){
							echo ' <a href="logout.php" title="se deconnecter"> Logout</a>';
						}
					?>
				</div>
				<div class="lien" style="float:right;">
					<?php
						if(!isset($_SESSION["id_user"])){
							echo '<a href="register.php" title="Sign up" class="link">Sign up</a> <br />';
							echo '<a href="login.php" title="Log in" class="link">Login</a>';
						}
					?>
				</div>
				<br />
				<br />
				<br />
				<br />
			</div>
			<div id="corps">
				<br />
				<?php
					include("database.php");
					$requete = "
						SELECT * 
						FROM jokes, users
						WHERE id_users_joke = id_users
						ORDER by jokes.score_joke DESC
					";
					$all_jokes = mysql_query($requete);
					while($info = mysql_fetch_assoc($all_jokes)){
						$id_joke=$info["id_joke"];
						echo '
							<div class="bloc_joke">
								
								<div class="user_joke">
									<img src="'.$info["avatar_users"].'" alt="avatar de '.$info["firstname_users"].' '.$info["surname_users"].'  " width="90px" height:"110px" />
									<br />
									<br />
									'.utf8_encode($info["pseudo_users"]).'
								
								</div>
								<div class="text_joke">
									<h2>'.utf8_encode($info["title_joke"]).' </h2>
									<br />
									<p>'.utf8_encode($info["text_joke"]).'</p>
								</div>
								<div class= "info_joke">
									<p>'.date("d/m/Y",$info["date_joke"]).'</p>
									<br />
									<p>score: '.$info["score_joke"].'</p>
									<br />';
									if(isset($_SESSION["id_user"])){
										$vote="
											SELECT *
											FROM vote_user
											WHERE id_user_vote=$id_user
											AND id_joke_vote=$id_joke
										";
										$user_vote=mysql_query($vote);
										if(mysql_num_rows($user_vote)==0){
											echo '	
												<form action="traitement.php" method="POST">
													<input type="hidden" value="'.$info["id_joke"].'" name="id_joke" />
													<input type="submit" value="vote" />
													</form>';
										}
									}
							echo '
								</div>
							</div>';
					}
				?>
		</div>
	</div>
		
</body>

</html>
